/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     
 * To Do        :
 ************************************************************************/
using System;
using SMLib.Automata.Base;
using System.Collections.Generic;
using SMLib.Automata.MM;

namespace SMLib.Automata.MM
{
	public class MM_Traces
	{
		public static void ReadInputFile (string filePath, ref List<Sequence> seqs, ref Alphabet alph)
		{
			alph = new Alphabet ();
			seqs = new List<Sequence> ();

			System.IO.StreamReader sr = new System.IO.StreamReader (filePath);
			string line;

			while ((line=sr.ReadLine())!=null) {
				Sequence sq = Sequence.Parse (line);
				seqs.Add (sq);
				foreach (PairOfSymbols p in sq.AllPairs())
					if (!alph.Contains (p.Input))
						alph.AddSymbol (p.Input);
			}
		}

		public static bool Verify (MealyMachine machine, List<Sequence> seqs)
		{
			bool error = false;
			foreach (Sequence s in seqs) {
				Word i=s.InputProjection();
				Word o1=s.OutputProjection();
				Word o2=machine.Output (i);
				if (!o1.Equals (o2)) {
					Console.WriteLine ("Error: output of " + i + " should be different!");
					error = true;
				}
			}
			return error;
		}
	}
}

